package com.socialuni.center.web.controller;

import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.center.web.model.RO.user.CenterMineUserDetailRO;
import com.socialuni.center.web.serive.UserService;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.model.UserEditVO;
import com.socialuni.sdk.repository.UserRepository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 查询用户详情
 *
 * @author qinkaiyuan
 * @since 1.0.0
 */
@RestController
@RequestMapping("socialuni/user")
public class UserController {
    @Resource
    private UserRepository userRepository;
    @Resource
    private UserService userService;

    @PostMapping("updateAvatar")
    public ResultRO<?> updateAvatar(@Valid @NotNull String avatar, UserDO user) {
        //被举报状态的用户不能修改
        user.setAvatar("https://" + avatar);
        user.setUpdateTime(new Date());
        userRepository.save(user);
        return new ResultRO<>();
    }

    @PostMapping("edit")
    public ResultRO<CenterMineUserDetailRO> editUser(@RequestBody @Valid UserEditVO userEditVO) {
        CenterMineUserDetailRO centerMineUserDetailRO = userService.editUser(userEditVO);
        return new ResultRO<>(centerMineUserDetailRO);
    }
}